//
//  AppDelegate.m
//  20240823
//
//  Created by 张伟 on 2024/8/23.
//

#import "AppDelegate.h"
#import "IQKeyboardManager.h"
#import "LockView.h"

@interface AppDelegate ()

@property (nonatomic) LockView * lockView;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    IQKeyboardManager.sharedManager.enable = true;
    IQKeyboardManager.sharedManager.shouldResignOnTouchOutside = true;
    
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
        
    // 获取 Main.storyboard 实例
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

    // 根据标识符实例化视图控制器
    ZWTabBarController *tabBarController = [storyboard instantiateViewControllerWithIdentifier:@"ZWTabBarController"];

    // 现在你可以使用 tabBarController 了，例如将其设置为根视图控制器
    self.window.rootViewController = tabBarController;
    [self.window makeKeyAndVisible];
    
    return YES;
}


- (void)applicationDidEnterBackground:(UIApplication *)application {

    BOOL open = [[NSUserDefaults.standardUserDefaults valueForKey:PROTECTION] boolValue];
    
    if (open) {
        if (![self.window.subviews containsObject:self.lockView]) {
            _lockView = [LockView viewFromNib];
            _lockView.frame = self.window.bounds;
            [self.window addSubview:self.lockView];
        }
    }
        
}


@end
